home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / dos_edit.arc / DOS-EDIT.DOC < prev    next >
Text File  |  1988-04-20  |  11KB  |  215 lines

  1.                             DOS-EDIT
  2.  
  3.                          Charles Petzold
  4.  
  5.  
  6. DOS command-line editing facilities are primitive at best. 
  7. Here's a memory-resident DOS-EDIT utility that saves you key
  8. strokes by providing full-screen editing.
  9.  
  10. How many times have you reached for the CursorUp key to correct
  11. something you've mistyped at the DOS command level?  I do it a
  12. lot.  It's almost instinctive.  The text is still there on the
  13. screen, so all you should have to do is move the cursor up, fix
  14. the text, and re-enter.  But this natural keyboard maneuver
  15. doesn't work in DOS.
  16.  
  17. I wrote DOS-EDIT to make it work.  DOS-EDIT is a resident program
  18. that allows you to move to, edit, and re-execute DOS commands
  19. that are still on the screen, much as you can with the BASICA
  20. interpreter.  And while of greatest use when you're on the DOS
  21. command level, DOS-EDIT will also work with such DOS programs as
  22. EDLIN or DEBUG, and with some other programs whose keyboard entry
  23. can be edited with the normal DOS editing keys (F1 to F5 and the
  24. cursor keys).
  25.  
  26. If you don't know about the DOS editing keys, you should at least
  27. start by learning about them.  Strangely enough, they got lost
  28. from PC-DOS 2.1 documentation when a separate User's Guide was
  29. split off from the main manual.  (The User's Guide for PC-DOS 3.0
  30. and 3.1 does describe them, and they do work under Version 2.1.) 
  31. The DOS editing keys themselves, however, can recall only the
  32. immediately previous command.  DOS-EDIT is often easier to use
  33. than the DOS editing keys even for that, and it can also retrieve
  34. other commands still on the screen, as well.
  35.  
  36. You can put DOS-EDIT.COM in your AUTOEXEC.BAT file so that it
  37. executes once and remains resident for the duration of your PC
  38. session.  Because it intercepts resident programs, particularly
  39. those that can be executed more than once.  If you use the DOS
  40. ASSIGN program, for example, you'll want to execute DOS-EDIT in
  41. your AUTOEXEC.BAT file before ASSIGN runs for the first time. 
  42. The same holds true for SIDEKICK.  In general, if DOS-EDIT does
  43. not seem to work at first, try placing it earlier in your
  44. AUTOEXEC.BAT and rebooting.
  45.  
  46.                     DOS-EDIT ON YOUR MACHINE
  47.  
  48. Once DOS-EDIT is loaded (normally through your AUTOEXEC.BAT
  49. file), you can best understand its operation by thinking of your
  50. keyboard input as being in one of two separate modes.  The normal
  51. mode works just as you're accustomed, and you won't know DOS-EDIT
  52. is even resident.  But when you press the Cursor up key, you
  53. enter the full-screen mode and DOS-EDIT kicks into action.
  54.  
  55. While in full-screen mode, you can use the cursor keys to move
  56. the cursor to any part of the screen above the line from which
  57. you started.  You are able to delete individual characters on the
  58. screen by pressing the Del key.  The rest of the line to the
  59. right of the deleted character moves left.  The Backspace key
  60. deletes the character to the left of the cursor and also moves
  61. the rest of the line left.  The PgDn key deletes all characters
  62. from the cursor to the end of the line.
  63.  
  64. You can also type in regular characters while in full-screen
  65. mode.  The typed characters will either overtype existing test or
  66. be inserted into the line.  The Ins key switches between these
  67. actions.  The program starts with insert off.
  68.  
  69. While in full-screen mode, the Home key moves the cursor horizon-
  70. tally to the original column position - the column the cursor was
  71. on when you entered full-screen mode - but keeps the cursor on
  72. the same line.  The PgUp key moves the cursor horizontally to the
  73. first column position of the current line, all the way over to
  74. the left of the screen.
  75.  
  76. You can exit from the full-screen mode and return to the line you
  77. started from in one of four different ways.  First, if you move
  78. the cursor down to the original line, the cursor will instantly
  79. jump back to its original position and you'll be out of full-
  80. screen mode.  Second, if you press Esc while in full-screen mode,
  81. you'll exit full screen mode with no changes made to your orig-
  82. inal line.  Third, if you press End, DOS-EDIT will transfer all
  83. text from the cursor to the end of the line (except trailing
  84. blanks) to the original line and leave the cursor at the end of
  85. the original line.  Fourth, pressing Enter does the same thing as
  86. End, except that it also enters the resulting command line.
  87.  
  88.                         HOW DO I USE IT?
  89.  
  90. The DOS-EDIT keystrokes may sound somewhat complex, but in actual
  91. use, you'll find them almost intuitive and simple to use.  The
  92. Home key is the most important.  Because Enter and End only move
  93. text that starts at the cursor position, you usually have to move
  94. the cursor to the beginning of the line, but not further left
  95. than the DOS prompt.  Assuming you enter full-screen mode with
  96. the cursor just to the right of the DOS prompt, Home moves it
  97. back to that position.
  98.  
  99. A few examples will clarify the keystrokes:
  100.  
  101. 1.  You entered a CD command but then realized you're on the
  102. wrong drive.  To fix matters at this point, type in the correct
  103. drive, move the cursor up the CD line, and press Enter.  (If the
  104. length of your prompt changes when you change drives, you must
  105. position the cursor under the C in CD before pressing Enter.)
  106.  
  107. 2.  You entered a long command but made a typing mistake.  Move
  108. the cursor up to the line, correct the mistake (using the Del and
  109. Backspace keys and inserting characters as appropriate), press
  110. Home, and then Enter.
  111.  
  112. 3.  You just did a DIR listing and you want to run one of the
  113. listed programs.  Move the cursor up the filename extension. 
  114. Press PgDn to delete from the cursor to the end of the line.  You
  115. can then enter any parameters, press PgUp to move the cursor to
  116. the left of the screen, and press Enter.  Or, after deleting the
  117. filename extension, you can press PgUp to move the cursor to the
  118. beginning of the line, and End to transfer the line down to the
  119. command line without entering it.  You may then enter the param-
  120. eters and press Enter.
  121.  
  122.                      A PROGRAMMER'S PROBLEM
  123.  
  124. I had originally wanted to make DOS-Edit work in exactly the same
  125. way as the BASICA interpreter.  That is, I wanted it to accept
  126. the entire line wherever the cursor was positioned on the line. 
  127. This didn't seem like a big deal, but programmers often find that
  128. a task that at first appears straightforward can develop an ugly
  129. little hitch on closer examination.
  130.  
  131. The hitch in this case proved to be the DOS prompt.  The DOS
  132. prompt is part of the line, but it is - inconveniently - a part
  133. of the line that DOS-EDIT must ignore.
  134.  
  135. Why not just have DOS-EDIT ignore the first two characters on the
  136. line?  No good.  Most hard disk users I know use the PROMPT
  137. command with a $p$g argument to display the current subdirectory,
  138. so their prompts are longer than two characters.  OK, then, why
  139. not just have DOS-EDIT ignore everything to the left of the first
  140. angle bracket character?  That might be fine for your prompt, but
  141. mine doesn't even end with a right-angle bracket.
  142.  
  143. The prompt problem was such a nuisance that I even went so far as
  144. to consider having DOS-EDIT look in the Environment area to get
  145. the actual prompt string so DOS-EDIT could know what it was and
  146. ignore it.  But a resident program like DOS-EDIT gets only a
  147. static copy of the Environment when it's loaded.  If you change
  148. the DOS prompt after DOS-EDIT is loaded, DOS-EDIT has no way of
  149. learning about the change.
  150.  
  151. That is why DOS-EDIT only transfers text from the cursor position
  152. on, and why I provided the Home key to move the cursor back to
  153. the original starting column.  When people ask of a program, "Why
  154. does it do it this way?" and "Wouldn't it make more sense to do
  155. it that way?" there are often good reasons.  In the case of DOS-
  156. EDIT, the prompt made me do it.
  157.  
  158.                    IT'S ALL IN THE INTERRUPTS
  159.  
  160. For an assembly language program that needs to get a whole line
  161. of keyboard input, the DOS Interrupt 21h function call 0Ah (Buf-
  162. fered Keyboard Input) is often ideal.  All the programmer has to
  163. do is set up an area in memory to receive the string of keyboard
  164. input, make the function call, and DOS does the rest.  After the
  165. user presses Enter, DOS returns the final string back to the
  166. program.
  167.  
  168. Moreover, if the string is returned intact to DOS the next time
  169. keyboard input is needed, DOS uses that string as a template and
  170. allows the user to recall and edit the string with the DOS func-
  171. tion keys.  (Because function call 0Ah is susceptible to Ctrl-
  172. Break and skips to a new line when the Esc key is pressed, it is
  173. not often used in more complex programs like spreadsheets and
  174. word processors.  These programs have their own logic to allow
  175. editing of command lines.)
  176.  
  177. Function call 0Ah is the one that COMMAND.COM, DEBUG, and EDLIN
  178. all use for keyboard input.  In one sense, all that DOS-EDIT has
  179. to do is add more functions to function call 0Ah to allow the
  180. user to move the cursor up to another part of the screen and
  181. retrieve previous commands or other text.  But since the workings
  182. of this function call are deep in the guts of DOS, DOS-EDIT has
  183. to do the job in a roundabout manner.
  184.  
  185. DOS-EDIT intercepts Interrupt 21h, but it only sets an internal
  186. flag if function call 0Ah is being requested.  It then just lets
  187. the normal function call proceed.  DOS-EDIT also intercepts
  188. Interrupt 16h, which is the BIOS service used for getting key-
  189. board input.  When DOS is getting keyboard input for function
  190. call 0Ah, it ultimately must go to Interrupt 16h.
  191.  
  192. DOS-EDIT monitors the Interrupt 16h calls for the Cursor up
  193. keystroke, which has no meaning to function call 0Ah.  When DOS
  194. is currently performing a function call 0Ah and Interrupt 16h is
  195. ready to pass back a Cursor up keystroke, DOS-EDIT kicks into
  196. action and goes into full-screen mode.
  197.  
  198. From that point on, DOS-EDIT is in control and handles all the
  199. cursor movement and editing of the display, using both Interrupt
  200. 16h and Interrupt 10h (the BIOS display interrupt).  When you
  201. press Enter or End, DOS-EDIT reads the line from the screen and
  202. goes out of full-screen mode.
  203.  
  204. At this point, DOS is still looking for keystrokes for its orig-
  205. inal function 0Ah call.  DOS-EDIT supplies these keystrokes from
  206. the text it read off the screen.  When this text is exhausted,
  207. DOS-EDIT relinquishes all control, and things return to normal
  208. again.
  209.  
  210. You'll probably find that DOS-EDIT is habit-forming.  It's one of
  211. those little utilities that after a little use almost seems like
  212. a proper part of DOS.  But of course, that's the power of resi-
  213. dent programs: They let us change and customize DOS to make it
  214. more flexible and easier to use.
  215.